﻿using System;
using WFC.BL.Interfaces.DomainModels;
using WFC.BL.Interfaces.Repositories;
using WFC.BL.Repositories;
using WFC.BL.Services.Interfaces;

namespace WFC.BL.Services
{
    public class PostService : IPostService
    {

        private IRepositoryFacade Repository { get; set; }

        /// <summary>
        /// Default constructor
        /// </summary>
        public PostService()
        {
            Repository = new RepositoryFacade();
        }

        #region IPostService Members

        public int InsertPosts(string title, string htmlContent, string shortDescription, string tags, int createdBy)
        {
            if (String.IsNullOrEmpty(title))
                throw new ArgumentNullException("title");

            if (String.IsNullOrEmpty(htmlContent))
                throw new ArgumentNullException("htmlContent");

            if (String.IsNullOrEmpty(tags))
                throw new ArgumentNullException("tags");

            return Repository.InsertPosts(title, htmlContent, shortDescription, tags, createdBy);
        }

        public IPostable ReadPostsById(int postId)
        {
            if (postId < 1)
                throw new ArgumentNullException("postId");

            return Repository.ReadPostsById(postId);
        }

        public bool UpdatePosts(IPostable post, int updatedBy)
        {
            if (post == null)
                throw new ArgumentNullException("post");

            if (updatedBy < 1)
                throw new ArgumentNullException("updatedBy");

            post.UpdatedBy = updatedBy;
            return Repository.UpdatePosts(post);
        }

        public bool DeletePosts(int postId)
        {
            if (postId < 1)
                throw new ArgumentNullException("postId");

            return Repository.DeletePosts(postId);
        }

        #endregion

    }
}
